void loop::check_mouse_hover()
{
    ray.setOrigin(n_cam->getPosition());
    ray.setDirection(n_cam->getOrientation() * Vector3(0,0,-1));
    rsq->setRay(ray);
    camera->getCameraToViewportRay(0.5f,0.5f,&ray);
    rsq->execute();
    //    typedef vector<RaySceneQueryResultEntry>::type RaySceneQueryResult;
    //for(RaySceneQueryResult::iterator
    //    a = rsq->getLastResults().begin(); a != rsq->getLastResults().end(); ++a)
    previous_rayed = current_rayed;
    if(! rsq->getLastResults().empty()) // we need to raycast each frame in order to know
    {        
        current_rayed = static_cast<Entity*>(rsq->getLastResults().begin()->movable);
        if(current_rayed != previous_rayed && previous_rayed != 0) // reset previous rayed
        {
            previous_rayed->setMaterialName("hover/idle");
            current_rayed->setMaterialName("hover/hover");
            //find_near_objects( // call there
            //    current_rayed->getParentSceneNode()->getPosition(), 5);
        }
    }
    else
        current_rayed->setMaterialName("hover/idle");
    
    //current_rayed->getMat
    //sphq->
}

void loop :: find_near_objects(Ogre::Vector3 pos, float radius)
{   // not callable yet
    sph.setCenter(pos);
    sph.setRadius(radius);
    //SceneQueryResult& b = sphq->execute();

    for(auto a = sphq->getLastResults().movables.begin(); a != sphq->getLastResults().movables.end(); ++a)
    { static_cast<Entity*>(*a)->setMaterialName("hover/hover");}
}
void loop :: setCameraMode   (int mode)
{
    /*
1. put a node (A) at the focus point you want to orbit around            # Target
2. make a child node (B) and set its position to (0,0, orbitdistance)    # cam
3. reset the orientation & position of the camera                        #
4. attach the camera to node B                                           # cam
5. optionally setFixedYaw on node A                                      #
6. to orbit, yaw and pitch node A based on the x/y of the mouse          #
    // root master target yaw pitch cam 
    */  // root master target yaw pitch cam 
    /* 
    default arch:
    root --> master --> target --> cam 
    yaw_pitch_ptr = target
    */
    if(mode == camera_mode) return;

    n_master -> detachAllObjects();     n_master -> removeAllChildren();
    n_target -> detachAllObjects();     n_target -> removeAllChildren();
    n_cam    -> detachAllObjects();     n_cam    -> removeAllChildren();
    n_recoil -> detachAllObjects();     n_recoil -> removeAllChildren();
    camera_mode = mode;

    REINIT (n_cam)
    REINIT (n_master)
    REINIT (camera)
    REINIT (n_target)
    REINIT (n_recoil)
    switch (mode)
    {
    case 1:
        /////////////////////
        n_master -> addChild(n_cam);
        n_cam -> addChild(n_recoil);
        n_master -> addChild(n_target); /////// MEH

        n_recoil     -> attachObject(camera);
        /////////////////////
        n_target->setFixedYawAxis(false);
        n_yawpitch_ptr = n_cam;
        break;

    case 3:
        /////////////////////
        n_master -> addChild(n_target);
        n_target -> addChild(n_cam);

        n_target -> attachObject(e_target);
        n_cam->setPosition(0,0,10);
        n_cam->attachObject(camera);
        /////////////////////
        n_target->setFixedYawAxis(true);
        n_yawpitch_ptr = n_target;
        break;
    default:
        exit(0xb00b);
        break;
    }
}

